package  ricky.quadtree
{
	import flash.geom.Rectangle;

	/**
	 * 普通四叉树
	 */
	public class QTree
	{
		function QTree(bounds:Rectangle, pointQuad:Boolean, maxDepth:int=NaN, maxChildren:int=NaN)
		{	
			var node;
			if(pointQuad)
			{
				
				node = new Node(bounds, 0, maxDepth, maxChildren);
			}
			else
			{
				node = new BoundsNode(bounds, 0, maxDepth, maxChildren);
			}
			
			this.root = node;
		}

		public var  root:Node;
		
		public function insert(item)
		{
			if(item instanceof Array)
			{
				var len = item.length;
				
				for(var i = 0; i < len; i++)
				{
					this.root.insert(item[i]);
				}
			}
			else
			{
				this.root.insert(item);
			}
		}
		
		public function clear()
		{
			this.root.clear();
		}
		
		public function retrieve(item)
		{
			//get a copy of the array of items
			var out = this.root.retrieve(item).slice(0);
			return out;
		}
	}
}